const user = [
  {
    id: 1,
    username: 'admin',
    password: '123456',
    nickname: '管理员',
    phone: '13800138000',
    email: 'admin@example.com',
    role: 'admin',
    status: 'active',
    createTime: '2024-01-01T10:00:00Z',
    lastLoginTime: '2024-01-10T15:30:00Z',
  },
  {
    id: 2,
    username: 'user1',
    password: '123456',
    nickname: '用户1',
    phone: '13900139000',
    email: 'user1@example.com',
    role: 'user',
    status: 'active',
    createTime: '2024-01-02T11:00:00Z',
    lastLoginTime: '2024-01-09T14:20:00Z',
  },
  {
    id: 3,
    username: 'user2',
    password: '123456',
    nickname: '用户2',
    phone: '13700137000',
    email: 'user2@example.com',
    role: 'user',
    status: 'inactive',
    createTime: '2024-01-03T12:00:00Z',
    lastLoginTime: '2024-01-08T13:10:00Z',
  },
  {
    id: 4,
    username: 'user3',
    password: '123456',
    nickname: '用户3',
    phone: '13600136000',
    email: 'user3@example.com',
    role: 'user',
    status: 'active',
    createTime: '2024-01-04T13:00:00Z',
    lastLoginTime: '2024-01-07T12:40:00Z',
  },
];

export default {
  'GET /api/user': (req: any, res: any) => {
    res.json({
      success: true,
      data: { user },
      total: user.length,
      errorCode: 0,
    });
  },
  'POST /api/user/add': (req: any, res: any) => {
    user.push({ id: user.length + 1, ...req.body });
    res.send({
      code: 200,
      success: true,
      message: '成功',
      data: req.body,
    });
  },
  'POST /api/user/update': (req: any, res: any) => {
    const index = user.findIndex((item) => item.id === req.body.id);
    if (index !== -1) {
      user[index] = req.body;
    }
    res.send({
      code: 200,
      success: true,
      message: '成功',
      data: req.body,
    });
  },
  'POST /api/user/delete': (req: any, res: any) => {
    const index = user.findIndex((item) => item.id === req.body.id);
    if (index !== -1) {
      user.splice(index, 1);
    }
    res.json({
      success: true,
      data: req.body.id,
    });
  },
};
